#include <iostream>
using namespace std;

class segmeng_gree {
	int seq[10000000]{};
	int sum[10000000 << 2]{};
	// int seq[20]{};
	// int sum[20 << 2]{};

	void up(int i)
	{
		sum[i] = sum[i << 1] + sum[(i << 1) + 1];
	}

	void build(int l, int r, int i)
	{
		if (l == r) {
			sum[i] = seq[l];
		} else {
			int mid = (l + r) >> 1;
			if (l <= mid) {
				build(l, mid, i << 1);
			}
			if (mid < r) {
				build(mid + 1, r, (i << 1) + 1);
			}
			up(i);
		}
	}

	int query(int jobl, int jobr, int l, int r, int i)
	{
		if (jobl <= l && r <= jobr) {
			return sum[i];
		}
		int ans = 0, mid = (l + r) >> 1;
		if (jobl <= mid) {
			ans += query(jobl, jobr, l, mid, i << 1);
		}
		if (mid < jobr) {
			ans += query(jobl, jobr, mid + 1, r, (i << 1) + 1);
		}
		return ans;
	}

    public:
	void run()
	{
		int n, m;
		cin >> n >> m;
		int maxn = -1;
		for (int i = 0, a; i < n; i++) {
			cin >> a;
			seq[++a] = 1;
			maxn = max(maxn, a);
		}

		build(1, maxn, 1);

		for (int i = 0, a, b; i < m; i++) {
			cin >> a >> b;
			a++;
			b++;
			if (maxn < a) {
				cout << 0 << '\n';
			} else if (maxn <= b) {
				cout << query(a, maxn, 1, maxn, 1) << '\n';
			} else {
				cout << query(a, b, 1, maxn, 1) << '\n';
			}
		}
	}
};

segmeng_gree sgt;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	sgt.run();
	return 0;
}